// src/mock/mock.js
import Mock from 'mockjs';


// import categoryBooksData from '/public/json/data1.json';


Mock.mock('/api/recent-search', 'get', () => {
    // 使用 mock.js 的 Random.ctitle() 来生成随机书名
    const randomBooks = [];
    for (let i = 0; i < 4; i++) {
        randomBooks.push(Mock.Random.ctitle(3, 5)); // 随机生成 3 到 5 个字的书名
    }
    return {
        code: 200,
        data: randomBooks
    };
});

// 猜你喜欢
Mock.mock('/api/recommended-books', 'get', () => {
    const books = Array.from({length: 4}, () => {
        const referenceBook = Mock.Random.ctitle(2, 7);
        return {
            title: Mock.Random.ctitle(5, 10),
            author: Mock.Random.cname(),
            cover: `https://picsum.photos/120/160?random=${Mock.Random.integer(1, 100)}`,
            recommendation: `阅读《${referenceBook}》的人也在读`
        };
    });
    return {code: 200, data: books};
});

// 飙升榜
Mock.mock('/api/mini-books', 'get', () => {
    const books = Array.from({length: 6}, () => {
        const isForeignAuthor = Mock.Random.boolean(); // 随机决定作者是否为外国人
        const author = isForeignAuthor
            ? `[${Mock.Random.pick(['美', '日', '韩', '英', '法'])}] ${Mock.Random.cname()}`
            : Mock.Random.cname();

        const recommendation = (Mock.Random.float(40, 99, 1, 1)).toFixed(1); // 推荐值范围在 40% 到 99%

        return {
            title: Mock.Random.ctitle(5, 10),
            author: author,
            cover: `https://picsum.photos/100/140?random=${Mock.Random.integer(1, 100)}`,
            recommendation: recommendation
        };
    });

    return {code: 200, data: books};
});

// 新书榜
Mock.mock('/api/news-books', 'get', () => {
    const books = Array.from({length: 6}, () => {
        const isForeignAuthor = Mock.Random.boolean(); // 随机决定作者是否为外国人
        const author = isForeignAuthor
            ? `[${Mock.Random.pick(['美', '日', '韩', '英', '法'])}] ${Mock.Random.cname()}`
            : Mock.Random.cname();

        const recommendation = (Mock.Random.float(40, 99, 1, 1)).toFixed(1); // 推荐值范围在 40% 到 99%

        return {
            title: Mock.Random.ctitle(5, 10),
            author: author,
            cover: `https://picsum.photos/100/140?random=${Mock.Random.integer(1, 100)}`,
            recommendation: recommendation
        };
    });

    return {code: 200, data: books};
});

// 总榜
Mock.mock('/api/all-books', 'get', () => {
    const books = Array.from({length: 6}, () => {
        const isForeignAuthor = Mock.Random.boolean(); // 随机决定作者是否为外国人
        const author = isForeignAuthor
            ? `[${Mock.Random.pick(['美', '日', '韩', '英', '法'])}] ${Mock.Random.cname()}`
            : Mock.Random.cname();

        const recommendation = (Mock.Random.float(40, 99, 1, 1)).toFixed(1); // 推荐值范围在 40% 到 99%

        return {
            title: Mock.Random.ctitle(5, 10),
            author: author,
            cover: `https://picsum.photos/100/140?random=${Mock.Random.integer(1, 100)}`,
            recommendation: recommendation
        };
    });

    return {code: 200, data: books};
});

// 神作榜
Mock.mock('/api/best-books', 'get', () => {
    const books = Array.from({length: 6}, () => {
        const isForeignAuthor = Mock.Random.boolean(); // 随机决定作者是否为外国人
        const author = isForeignAuthor
            ? `[${Mock.Random.pick(['美', '日', '韩', '英', '法'])}] ${Mock.Random.cname()}`
            : Mock.Random.cname();

        const recommendation = (Mock.Random.float(90, 99, 1, 1)).toFixed(1); // 推荐值范围在 90% 到 99%

        return {
            title: Mock.Random.ctitle(5, 10),
            author: author,
            cover: `https://picsum.photos/100/140?random=${Mock.Random.integer(1, 100)}`,
            recommendation: recommendation
        };
    });

    return {code: 200, data: books};
});

// 分类数据
Mock.mock('/api/categories', 'get', () => {
    const categories = [
        {
            id: 1,
            name: '精品小说',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 2)},',
            bookCount: 23902
        },
        {
            id: 2,
            name: '历史',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 3)},',
            bookCount: 12345
        },
        {
            id: 3,
            name: '文学',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 4)},',
            bookCount: 6543
        },
        {
            id: 4,
            name: '艺术',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 5)},',
            bookCount: 4321
        },
        {
            id: 5,
            name: '人物传记',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 6)},',
            bookCount: 9876
        },
        {
            id: 6,
            name: '哲学宗教',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 7)},',
            bookCount: 2345
        },
        {
            id: 7,
            name: '计算机',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 8)},',
            bookCount: 8765
        },
        {
            id: 8,
            name: '心理',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 9)},',
            bookCount: 1324
        },
        {
            id: 9,
            name: '社会文化',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 10)},',
            bookCount: 4678
        },
        {
            id: 10,
            name: '个人成长',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 11)},',
            bookCount: 2567
        },
        {
            id: 11,
            name: '经济理财',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 12)},',
            bookCount: 1452
        },
        {
            id: 12,
            name: '政治军事',
            image: 'https://picsum.photos/100/140?random=${Mock.Random.integer(1, 99)},',
            bookCount: 7890
        }
    ];

    return {code: 200, data: categories};
});







